<%-- 
    Document   : giohang
    Created on : Oct 13, 2011, 7:40:58 PM
    Author     : Rocker000
--%>

<%@page import="pojo.SanPham_pojo"%>
<%@page import="dao.SanPham_dao"%>
<%@page import="pojo.ChiTietGioHang_pojo"%>
<%@page import="java.util.ArrayList"%>
<%@page import="pojo.KhachHang_pojo"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    String err = "";
    if(request.getAttribute("err_giohang")!=null)
         err = String.valueOf(request.getAttribute("err_giohang"));
    KhachHang_pojo kh = new KhachHang_pojo();
    if(session.getAttribute("KhachHang")!=null)
        kh = (KhachHang_pojo)session.getAttribute("KhachHang");
//Lấy danh sách chi tiết gio hang(gio hang) 
    ArrayList<ChiTietGioHang_pojo> ds = new ArrayList<ChiTietGioHang_pojo>();
    if(session.getAttribute("GioHang")!=null) {        
        ds =  (ArrayList<ChiTietGioHang_pojo>)session.getAttribute("GioHang");}
    double tonggiatri = 0;
%>  
          
<form id="form1" name="form1" method="get" action="giohang_controller">
<table width="100%" border="1" background="Image/main.jpg">
  <tr>
    <td width="4%" align="center" valign="middle" bgcolor="#FFFFFF"><h2>&nbsp;</h2></td>
    <td width="20%" align="center" valign="middle"><strong><font color="#FF0000">Sản phẩm</font></strong></td>
    <td width="17%" align="center" valign="middle"><strong><font color="#FF0000">Hình ảnh</font></strong></td>
    <td width="20%" align="center" valign="middle"><strong><font color="#FF0000">Số lượng</font></strong></td>
    <td width="14%" align="center" valign="middle"><strong><font color="#FF0000">Giá</font></strong></td>
    <td width="25%" align="center" valign="middle" bgcolor="#FFFFFF"><h2>&nbsp;</h2></td>
    </tr>
    <%for(int i =0;i<ds.size();i++){ChiTietGioHang_pojo ct=ds.get(i);SanPham_pojo sp =SanPham_dao.LaySanPhamTheoMa(ct.getMasanpham()); %>   
  <tr>
    <td align="center" valign="middle">
        <a href="giohang_controller?action=xoachitiet&&machitiet=<%=ct.getMachitiet() %>">
        <input type="button" name="btxoa" id="btxoa" value="Xóa" />
        </a>
    </td>
    <td align="center" valign="middle"><%=sp.getTenSanPham() %></td>
    <td align="center" valign="middle"><img src="<%=sp.getImage() %>" width="100px" height="100px" /></td>
    <td align="center" valign="middle"><input type="text" name="txtsoluong" id="txtsoluong" value="<%=ct.getSoluong() %>" /></td>
    <td align="center" valign="middle"><%=sp.getGia()*ct.getSoluong() %></td>
    <td align="center" valign="middle"><a href="muasanpham.jsp?masanpham=<%=sp.getMaSanPham() %>"><input type="button" name="btmua" id="btmua" value="Mua sản phẩm này" /></a></td>
    </tr>
    <%tonggiatri = tonggiatri+ sp.getGia()*ct.getSoluong();}%>
    
  <tr>
      <td colspan="6" align="center" valign="middle"><font color="#FF0000">Tổng giá trị: <strong><%=tonggiatri%> K</strong></font></td>
    </tr>
  <tr>
    <td colspan="6" align="center" valign="middle"><table width="100%" border="0">
      <tr align="center">
        <td>
            <input type="hidden" name="action" value="capnhatgiohang">
            <input type="submit" name="btcapnhat" id="btcapnhat" value="Cập nhật giỏ hàng" />
        </td>
        <td><a href="giohang_controller?action=muahet"><input type="button" name="btmuahet" id="btmuahet" value="Mua toàn bộ " /></a></td>
        <td><a href="giohang_controller?action=xoahet"><input type="button" name="btxoahet" id="btxoahet" value="Xóa giỏ hàng" /></a></td>
        <td><a href="giohang_controller?action=luugiohang"><input type="button" name="btluu" id="btluu" value="Lưu lại giỏ hàng" /></a></td>
        </tr>
    </table></td>
    </tr>
    <tr>
        <td colspan="6" align="center" valign="middle">
            <Strong><font color="green"><%=err%></font><strong>
        </td>
    </tr>
</table>
</form>
